package com.wlyuan.index.domain.source.assembler;

import com.wlyuan.core.marker.NamedUtils;
import com.wlyuan.core.marker.ValueUtils;
import com.wlyuan.finance.dto.IndexBillRelationEventDTO;
import com.wlyuan.index.api.dto.waybill.BillIndexDTO;
import com.wlyuan.index.domain.source.utils.SourceUtils;
import com.wlyuan.index.domain.source.valueobj.Bill;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.var;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.ArrayList;
import java.util.List;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class BillAssembler {
    @Mapper(uses = {ValueUtils.class, NamedUtils.class, SourceUtils.class})
    public interface Assembler {
        Bill assemble(BillIndexDTO source, IndexBillRelationEventDTO relation);
    }

    private static final Assembler ASSEMBLER = Mappers.getMapper(Assembler.class);

    public static List<Bill> assemble(BillIndexDTO source) {
        var balances = new ArrayList<Bill>();
        balances.add(ASSEMBLER.assemble(source, source.getDownstream()));
        balances.add(ASSEMBLER.assemble(source, source.getUpstream()));
        return balances;
    }
}
